package com.zoran.study.spring.common;

/**
 * Define a business error code.
 *
 * You should define your own business error codes by implementing this
 * interface.
 * <p>
 * E.g.
 *
 * <pre>
 * public enum BusinessErrors implements ErrorCode {
 *
 *     ONE_ERROR(110001),
 *
 *     // ......
 *
 *     ANOTHER_ERROR(110101);
 *
 *     private final int code;
 *
 *     private CommonErrors(int code){
 *     this.code=code;
 *     }
 *
 *     &#64;Override
 *     public int code() {
 *         return code;
 *     }
 *
 *     &#64;Override
 *     public String messageKey() {
 *         return name().replace('_', '.').toLowerCase();
 *     }
 *
 * }
 * </pre>
 *
 * <b>N.B.</b> Follow this convention to define error codes:
 * <ol>
 * <li>Error code has 6 digits, and is divided into 4 parts: [1][A][BB][CC];
 * <li>Highest digit must be 1;
 * <li>[A] represents your business;
 * <li>[BB] defines error category;
 * <li>[CC] defines concrete error code.
 * </ol>
 *
 * <b>N.B.</b> Common error message i18n resources locate in /resources/i18n.
 * Make sure your i18n resources locate in a different location, e.g.
 * /resources/error, otherwise, common's will not be loaded.
 *
 * @author Winter Gao
 *
 */
public interface ErrorCode {

    int code();

    String messageKey();

}
